//
//  94. 二叉树的中序遍历.swift
//  Top600
//
//  Created by rjb on 2021/8/10.
//

import Foundation
class Solution94 {
    var result: [Int] = []
    func inorderTraversal(_ root: TreeNode?) -> [Int] {
        inorder(root)
        return result
    }
    func inorder(_ node: TreeNode?) {
        guard let node = node else {
            return
        }
        inorder(node.left)
        result.append(node.val)
        inorder(node.right)
    }
    
    static func test() {
        let solution = Solution94()
        let node1 = TreeNode(1)
        let node2 = TreeNode(2)
        let node3 = TreeNode(3)
        
        node1.right = node2
        node2.left = node3
        
        let result  = solution.inorderTraversal(node1)
        print(result)
    }
}
